package com.intech.android.demo.cms.beans;

import com.intech.android.demo.cms.common.Constants;
import com.intech.android.demo.cms.common.FacesHelper;
import com.intech.android.demo.cms.common.Util;
import com.intech.android.demo.cms.decorators.RegionDecorator;

import java.util.ArrayList;
import java.util.List;

public class RegionBean
{
    private String newName;
    private String newLicenseCapacity;
    private String region_ID = "4";
    List<RegionDecorator> regionDecorators;

    private void fillRegionListTempValues()
    {
        regionDecorators = new ArrayList<RegionDecorator>();
        regionDecorators.add(new RegionDecorator(1, "Mumbai", "9111,9112,9113"));
        regionDecorators.add(new RegionDecorator(2, "Delhi", "9221,9222,9223"));
        regionDecorators.add(new RegionDecorator(3, "Bangalore", "9331,9332,9333"));
        regionDecorators.add(new RegionDecorator(4, "Calcutta", "9441,9442,9443"));
    }

    public String addRegion()
    {
        newName = "";
        newLicenseCapacity = "";
        region_ID = "4";
        return Constants.Navigation.ADD_REGION_LINK;
    }

    public String editRegion()
    {
        Integer region_id = FacesHelper.getParameterAsInteger("edit_region");
        if (region_id == null)
        {
            return Constants.Navigation.REGIONS_LINK;
        }
        fillAddRegionForm(region_id);
        return Constants.Navigation.ADD_REGION_LINK;
    }

    private void fillAddRegionForm(Integer regionNumber)
    {
        RegionDecorator currentDecorator = new RegionDecorator();
        for (RegionDecorator regionDecorator : regionDecorators)
        {
            if (Integer.parseInt(regionDecorator.getId()) == regionNumber)
            {
                currentDecorator = regionDecorator;
            }
        }

        region_ID = currentDecorator.getId();
        newName = currentDecorator.getName();
        newLicenseCapacity = currentDecorator.getLicenseCapacity();
    }

    public String saveEditedRegion()
    {
        return Constants.Navigation.REGIONS_LINK;
    }

    public List<RegionDecorator> getRegionDecorators()
    {
        if (Util.isEmpty(regionDecorators))
        {
            fillRegionListTempValues();
        }
        return regionDecorators;
    }

    public void setRegionDecorators(List<RegionDecorator> regionDecorators)
    {
        this.regionDecorators = regionDecorators;
    }

    public String getNewName()
    {
        return newName;
    }

    public void setNewName(String newName)
    {
        this.newName = newName;
    }

    public String getNewLicenseCapacity()
    {
        return newLicenseCapacity;
    }

    public void setNewLicenseCapacity(String newLicenseCapacity)
    {
        this.newLicenseCapacity = newLicenseCapacity;
    }

    public String getRegion_ID()
    {
        return region_ID;
    }

    public void setRegion_ID(String region_ID)
    {
        this.region_ID = region_ID;
    }
}
